package com.keyancompany.zhongbaopingtai.activity;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;

import com.keyancompany.zhongbaopingtai.Constants;
import com.keyancompany.zhongbaopingtai.R;
import com.keyancompany.zhongbaopingtai.adapter.IFragmentPagerAdapter;
import com.keyancompany.zhongbaopingtai.fragment.MyTaskFragment;
import com.keyancompany.zhongbaopingtai.utils.IntentUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.BindString;

/**
 * @author firefox
 *         我的任务/任务看板
 */
public class MyTaskActivity extends BaseActivity {
    @BindString(R.string.my_task)
    String title;
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.tabLayout)
    TabLayout tabLayout;
    @Bind(R.id.complaint_viewpager)
    ViewPager complaintViewpager;

    private String teamCode;

    @Override
    protected int getContentViewId() {
        return R.layout.layout_tab_viewpager;
    }

    @Override
    protected int getMenuId() {
        return R.menu.publish_package_menu;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.action_publish_package) {
            IntentUtils.startActivity(mContext, CreateTaskActivity.class, Constants.TEAM_CODE, teamCode);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void initToolBar() {
        initToolBar(toolbar, title);
    }

    @Override
    protected void setUpViews() {
        teamCode = getIntent().getStringExtra(Constants.TEAM_CODE);
        initTab();
    }


    private void initTab() {

        tabLayout.addTab(tabLayout.newTab());
        List<Fragment> tcf = new ArrayList<>();

        tcf.add(MyTaskFragment.newInstance(0, teamCode));
        tcf.add(MyTaskFragment.newInstance(1, teamCode));

        final IFragmentPagerAdapter pagerAdapter = new IFragmentPagerAdapter(getSupportFragmentManager(), tcf);

        String tabTitles[] = mContext.getResources().getStringArray(R.array.my_task_state);

        pagerAdapter.setTitles(tabTitles);
        complaintViewpager.setAdapter(pagerAdapter);


        tabLayout.setupWithViewPager(complaintViewpager);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
    }


}